Summary

This is a Java programming past paper from 2019. It contains questions on topics such as arithmetic operations, converting temperature, printing numbers, and checking prime numbers. The questions are suitable for secondary school students.

Full Transcript

Java Programming CS II Yr Java Programming SECTION-I 1. (a)Write a simple Java Program to Add, Subtract, Multiply and divide two inte...

Java Programming CS II Yr Java Programming SECTION-I 1. (a)Write a simple Java Program to Add, Subtract, Multiply and divide two integers. class ArithmeticOperations { public static void main(String args[]) { int a , b ,x1,x2,x3,x4 ; a = 10 ; b=6; x1 = a+b; x2 = a-b; x3 = a*b; x4 = a/b; System.out.println("a = "+ a + " b= " + b); System.out.println("a + b = "+ x1); System.out.println("a - b = "+ x2); System.out.println("a * b = "+ x3); System.out.println("a / b = "+ x4); } } Output a = 10 b= 6 a + b = 16 a-b=4 a * b = 60 a/b=1 PV.Ramana-Govt. Jr College (Boys), Nizamabad Page 1 Java Programming CS II Yr (b) Write a Java program to convert the temperature from the command line In Celsius to Fahrenheit. // converts temperature from celsius to fahrenheit importjava.util.*; classCelsiusToFahrenheit { public static void main(String args[]) { floatc,f ; Scanner in = new Scanner(System.in); System.out.println("Enter temperature in Celsius"); c = in.nextInt(); f = 9*c/5 + 32; System.out.println("Temperature in Celsius = " + c); System.out.println("Temperature in Fahrenheit = " + f); } } input Enter temperature in Celsius 0 output Temperature in Celsius = 0.0 Temperature in Fahrenheit = 32.0 input Enter temperature in Celsius 100 output Temperature in Celsius = 100.0 Temperature in Fahrenheit = 212.0 input Enter temperature in Celsius 34 output Temperature in Celsius = 34.0 Temperature in Fahrenheit = 93.2 PV.Ramana-Govt. Jr College (Boys), Nizamabad Page 2 Java Programming CS II Yr input Enter temperature in Celsius -40 output Temperature in Celsius = -40.0 Temperature in Fahrenheit = -40.0 2. (a)Write a Java program to print numbers from 1 to n using the do...While structure. importjava.util.Scanner; class numbers { public static void main(String args[]) { intn,i; System.out.println("enter an integer"); Scanner in = new Scanner(System.in); n= in.nextInt(); i=1; do { System.out.println(i); i=i+1; } while(i

Use Quizgecko on...
Browser
Browser