楼主: ReneeBK
2250 19

Hari Mohan Pandey:Java Programming [推广有奖]

  • 1关注
  • 62粉丝

VIP

已卖:4897份资源

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49635 个
通用积分
55.7537
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57805 点
帖子
4005
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

楼主
ReneeBK 发表于 2015-5-31 04:02:09 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

  • Java Programming
  • By: Hari Mohan Pandey

  • Publisher: Pearson India

  • Pub. Date: December 12, 2011

  • Print ISBN-10: 81-317-3311-4

  • Print ISBN-13: 978-81-317-3311-0

  • Web ISBN-10: 81-317-6536-9

  • Web ISBN-13: 978-81-317-6536-4

  • Pages in Print Edition: 880

  • Subscriber Rating: [5 Ratings] Subscriber Reviews



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Programming Program gram Ming Prog Java

本帖被以下文库推荐

沙发
ReneeBK 发表于 2015-5-31 04:04:19
  1. /*PROG 4.1 DEMO OF IF VER 1 */
  2. import java.io.*;
  3. import java.util.*;
  4. class JPS1
  5. {
  6.    public static void main(String args[])
  7.    {
  8.        Scanner sc = new Scanner (System.in);
  9.        System.out.print("\n\nEnter an integer number:=");
  10.        int x = sc.nextInt();
  11.        if (x>=100)
  12.        {
  13.           System.out.println("\n x is greater or equal to 100\n");
  14.           System.out.println("\n You think better\n");
  15.        }
  16.        System.out.println("\n x is less than 100\n");
  17.    }
  18. }
复制代码


Explanation: Here the statements after if expression are put in the braces. When the if condition is true, all the statements within the braces get executed; in case the condition is false, the statements within the braces are skipped. Regardless of true/falsity of if condition, the remaining statements are executed and so is the output. To execute only if-dependent statements, one will have to use if-else construct or terminate the program after the execution of if block. The second alternative is shown in the next program.

藤椅
ReneeBK 发表于 2015-5-31 04:05:44
  1. /*PROG 4.2 DEMO OF IF VER 3 */
  2. class JPS3
  3. {
  4.    public static void main(String args[])
  5.    {
  6.          boolean x = false;
  7.          if (x)
  8.          {
  9.                 System.out.println("\n X is greater or equal
  10.                                                   to 100");
  11.                 System.out.println("\n You think better");
  12.                 System.exit(0);
  13.          }
  14.          System.out.println("\n X is less than 100");
  15.    }
  16. }
复制代码

Explanation: In Java, if(x) is equivalent to if(!x 5 false) and x can only be Boolean value. Similarly, if(!x) is equivalent to if(x = = false).


板凳
ReneeBK 发表于 2015-5-31 04:08:45
  1. /*PROG 4.3 PROGRAM TO CHECK NUMBER IS EVEN OR ODD */
  2. import java.io.*;
  3. import java.util.*;
  4. class JPS4
  5. {
  6.    public static void main(String args[])
  7.    {
  8.           int x;
  9.           Scanner sc = new Scanner(System.in);
  10.           PrintStream pr = System.out;
  11.           pr.println("\n Enter an Integer number");
  12.           x = sc.nextInt();
  13.           if (x % 2 == 0)
  14.                  pr.println("Number " + x + " is even");
  15.           else
  16.           pr.println("Number " + x + " is odd");
  17.    }
  18. }
复制代码

Explanation:
As discussed earlier, System.out is an object of class PrintStream so it is assigned to a reference pr of PrintStream type. Now instead of writingSystem.out.println, you can write pr.println. If the if condition x%2 = = 0 is true, the number is even, else the number is not even. The else part executes only when if part is false and vice-versa. In the program both if and else parts contain just one statement to be dependent on them so braces are not needed; however, if you put the braces there will not be any harm.


报纸
ReneeBK 发表于 2015-5-31 04:10:42
  1. /*PROG 4.4 MAXIMUM OF TWO NUMBERS */
  2. import java.io.*;
  3. import java.util.*;
  4. class JPS5
  5. {
  6.    public static void main(String[] args)
  7.    {
  8.           int x, y;
  9.    Scanner sc = new Scanner(System.in);
  10.           System.out.print("\nEnter first number :=");
  11.           x = sc.nextInt();
  12.           System.out.print("\nEnter second number:=");
  13.           y = sc.nextInt();
  14.           if (x == y)
  15.           {
  16.                  System.out.println("\nBoth are equal");
  17.                  System.exit(0);
  18.           }
  19.           if (x > y)
  20.                  System.out.println("\nMaximum is " + x);
  21.           else
  22.                  System.out.println("\nMaximum is " + y);
  23.    }
  24. }
复制代码
Explanation:
  • Program is self-explanatory.

地板
ReneeBK 发表于 2015-5-31 04:14:23
  1. /*PROG 4.5 MAXIMUM OF THREE NUMBERS USING NESTING OF IF-ELSE STATEMENT */
  2. import java.io.*;
  3. import java.util.*;
  4. class JPS6
  5.    {
  6.           public static void main(String args[])
  7.           {
  8.              int a, b, c, d = 0;
  9.              Scanner sc = new Scanner(System.in);
  10.              System.out.println("\nEnter three number");
  11.              a = sc.nextInt();
  12.              b = sc.nextInt();
  13.              c = sc.nextInt();
  14.              if ((a == b) && (a == c))
  15.                   System.out.println("All three are equal\n");
  16.              else
  17.              {
  18.                  if (a > b)
  19.                  {
  20.                        if (a > c)
  21.                            d = a;
  22.                        else
  23.                            d = c;
  24.                  }
  25.                  else
  26.                  {
  27.                        if (b > c)
  28.                            d = b;
  29.                        else
  30.                            d = c;
  31.                  }
  32.              }
  33.              System.out.println("Maximum is " + d);
  34.    }
  35. }
复制代码
Explanation:If the numbers are equal the first if condition is true else else block is executed. In the else part, there is one more if-else. If a > b is true then inside this if block, using one more if-else it is checked whether a > c, if this is so then a is greater else c is greater.

If the first if condition is false in the else block then else part of the inner if executes which means b > a. Inside this inner else one more if-else checks whether b > c, if it is so then b is greater else c is greater.

7
ReneeBK 发表于 2015-5-31 04:17:21
  1. /*PROG 4.6 FINDING ROOTS OF THE QUADRATIC EQUATION */
  2. import java.io.*;
  3. import java.util.*;
  4. class JPS8
  5. {
  6.    public static void main(String args[])
  7.    {
  8.           double a, b, c, r1, r2, dis;
  9.           Scanner sc = new Scanner(System.in);
  10.           System.out.print("\n\nEnter value of A :=");
  11.           a = sc.nextDouble();
  12.           System.out.print("Enter value of B :=");
  13.           b = sc.nextDouble();
  14.           System.out.print("Enter value of C :=");
  15.           c = sc.nextDouble();
  16.           dis = b * b - 4 * a * c;
  17.           if (dis < 0)
  18.                  System.out.print("\nRoots are imaginary\n");
  19.           else if (dis == 0)
  20.           {
  21.                  System.out.print("\nRoots are equal\n");
  22.                  r1 = -b / (2 * a);
  23.                  r2 = b / (2 * a);
  24.                  System.out.print("\nRoot1 or r1 := "
  25.                                     +r1+"\n");
  26.                   System.out.print("\nRoot2 or r2 := "
  27.                                     +r2+"\n");
  28.           }
  29.           else
  30.           {
  31.                  System.out.println("\n Roots are
  32.                                         unequal\n");
  33.                  r1 = (-b + Math.sqrt(dis)) / (2.0 * a);
  34.                  r2 = (-b + Math.sqrt(dis)) / (2.0 * a);
  35.                  System.out.print("\nRoot1 or r1:= "
  36.                                      +r1+"\n");
  37.                  System.out.print("\nRoot2 or r2:= "
  38.                                      +r2+"\n");
  39.           }
  40.    }
  41. }
复制代码
Explanation:

The quadratic equation in mathematics is given as follows:

AX2 + BX + C = 0,

where, A, B and C are constants. The solution of the equation comprises two roots as power of X is 2.

R1 = (-B + sqrt (B * B - 4 * A * C)) / 2 * A

R2 = (-B - sqrt (B * B - 4 * A * C)) / 2 * A

The expression B * B - 4 * A * C is known as discriminant (say dis), and on the basis of its value the roots are determined as equal (dis = = 0) imaginary (dis < 0) or unequal (dis > 0) as shown in the above program.

In the program, the value of three constants are taken as output using A, B and C and the value of dis is calculated.

8
ReneeBK 发表于 2015-5-31 04:19:57
  1. /*PROG 4.7 TO DETERMINE THE STATUS OF ENTERED CHARACTER */
  2. import java.io.*;
  3. class JPS9
  4. {
  5.    public static void main(String args[])
  6.    {
  7.    char c;
  8.    try
  9.    {
  10.           DataInputStream input;
  11.           input=new DataInputStream(System.in);
  12.            System.out.println("Enter a character");
  13.           c=(char)(input.read());
  14.           if(c>=65 && c <=90)
  15.               System.out.println("You have entered
  16.                                   uppercase letter\n");
  17.           else if(c>=97&&c<=122)
  18.               System.out.println("You have entered
  19.                                   lowercase letter\n");
  20.           else if(c>=48 && c<=57)
  21.               System.out.println("You have eneterd a digit\n");
  22.           else
  23.               System.out.println("You have entered a
  24.                                   special symbol\n");
  25.       }
  26.           catch(Exception eobj)
  27.           {
  28.               System.out.println("ERROR!!!!");
  29.           }
  30.       }
  31. }
复制代码
Explanation:
The ASCII/unicode values is from 97 to 122 (inclusive both) for lowercase alphabets and 65 to 90 (inclusive both) for uppercase alphabets. It is checked whether the entered character is within these two ranges using else-if ladder. Similarly ASCII/Unicode values for digits are from 48 to 57 (inclusive both), so character entered is also checked with this range. If all the three conditions fail then the character entered must be a special symbol.

9
ReneeBK 发表于 2015-5-31 04:22:23
  1. /*PROG 4.8 DEMO OF SWITCH-CASE VER 1 */
  2. import java.io.*;
  3. import java.util.*;
  4. class JPS10
  5. {
  6.    public static void main(String args[])
  7.    {
  8.           Scanner sc=new Scanner(System.in);
  9.           System.out.print("\n Enter 0, 1, or 2 :=");
  10.           int num = sc.nextInt();
  11.           switch (num)
  12.           {
  13.             case 0:
  14.                    System.out.println("\n U entered zero\n");
  15.                    break;
  16.             case 1:
  17.                    System.out.println("\n U entered one\n");
  18.                    break;
  19.             case 2:
  20.                    System.out.println("\n U enterd two\n");
  21.                    break;
  22.             default:
  23.                    System.out.println("\n U entered other
  24.                                     than 0,1,or 2\n");
  25.          }
  26.    }
  27. }
复制代码
Explanation:
There is no break statement in case 1, so both case 1 and case 2 are assumed to be true and so is the output. In fact, due to the absence of break statement in the second case, rest of the statements are considered part of the second case till a break is not found. Break in case 2 causes control to come out from switch. If break were not in case 2 also then default would have got executed too.

10
ReneeBK 发表于 2015-5-31 04:24:20
  1. /*PROG 4.9 GENERATING TABLE OF A GIVEN NUMBER */
  2. import java.io.*;
  3. import java.util.*;
  4. class JPS12
  5. {
  6.    public static void main(String args[])
  7.    {
  8.           int num, t = 1, value;
  9.           Scanner sc = new Scanner(System.in);
  10.           System.out.print("\nEnter any +ve number:= ");
  11.           num = sc.nextInt();
  12.           System.out.println("\nThe table of "+num+" is
  13.                                  given below\n");
  14.           while (t <= 10)
  15.           {
  16.                 value = num * t;
  17.                 System.out.println(num + " x " + t + " = " +
  18.                                    value);
  19.                 t++;
  20.            }
  21.    }
  22. }
复制代码
Explanation:
Any +ve number is taken as input. The number n is multiplied by 1 through 10 inside the loop and the loop counter; the number and value are displayed by formatting as to produce the desired output.

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
jg-xs1
拉您进交流群
GMT+8, 2026-1-1 16:33