0% found this document useful (0 votes)
4 views

Assignment 1

The document provides instructions for 10 programming exercises involving Java concepts like variables, methods, input/output, conditionals, and loops. Students are asked to write Java code that prints hello world, checks for errors, sorts values, calculates formulas, checks for leap years, finds day of weeks, and calculates wind chill among other tasks.

Uploaded by

sasanaravi2020
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment 1

The document provides instructions for 10 programming exercises involving Java concepts like variables, methods, input/output, conditionals, and loops. Students are asked to write Java code that prints hello world, checks for errors, sorts values, calculates formulas, checks for leap years, finds day of weeks, and calculates wind chill among other tasks.

Uploaded by

sasanaravi2020
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment 1

Instructions: use camel case for variable name and method


name.
Exercise 1 : Hello World:

Write the program and compile the code @ command line to execute
class hello {
public static void main (String[]arg){
System.out.print("Hello, ");
//read your friend name
System.out.print(arg[0]);
System.out.println(“Good Morning!”);
}
}

Exercise 2:Error message

Find the maximum Compile time and Runtime error messages of simple one line
output message.
Example

 Delete any of the semicolons.


 Misspell the word public, static, void, main
 omit the word public, static, void, main
 Remove the quotation marks around string
 Remove the curly braces

Exercise 3: Write a program that takes three inputs and print them in ascending
order and descending order

Exercise 4: Write the program that prints correct output for the formula
F=𝐺 ∗ 𝑀1 ∗ 𝑀2/𝑅2 . Correct the given statement and output the required result.

Exercise 5 : Find error messages


Copy the program and compile it. Find the error messages that the compiler finds out. Correct
it out and repeat the process until the code runs
Class Bug{
public static int main (intparam) {
string name
Scanner in=new Scanner(System.in);
System.out.println("Hello. Please type your name:);
name = in.readline();
system.out.println("Hello"+name);
System.out.println (“Have a,
nice day!)
}
}

Exercise 6: Conversation
Write a Java program to create a Conversation between you and your friend
What is your name?
James
Hi James. How do you do?
I'm fine. thanks.
I'm glad to see you James. What type of Programming language do you like?
Java

I like Java too. Do Python finds a good replacement for Java?


No
You say "No." I wonder why that is?
Because I am familiar with Java.
I'm happy to talk with you that but I have to go now. Bye

Exercise 7: Leap year


Write a program to check if the given year is a leap year or not.
Your input is an integer (year). The program should print a Boolean
value: True if the year is a leap year, False if not.
Constraint
year ≥ 1000
Input: 2024
Output: True
Input: 2025
Output: False

Exercise 8: Day of the Week

Write a program that takes a date as input and prints the day of the week that
date falls on. Read the three int input as m(month), d(day) and y(year). Use 1 of
m for January, 2 for February, and so forth. For output print 0 for Sunday, 1 for
Monday and so forth. Use the following formula for the Gregorian calendar.
Exercise 9 : Wind Chill
Given the temperature (in degrees) and the wind speed v(in miles per hour), the
Weather service outputs the temperature(wind chill) as follows. Read
temperature and velocity from user and print the wind chill. Use Math.pow(a,b)
for a^b. The input in invalid if the T value is larger than 50 and v value larger
than 120 or less than 3(Assume the tange of the value fall in that range)

Exercise 10:Write a program to create following series by using the integers a,


b,c n.
𝑎 + 30 . 𝑏 0 . 𝑐 , 𝑎 + 30 . 𝑏 0 . 𝑐 + 31 . 𝑏1 . 𝑐 , (𝑎 + 30 . 𝑏 0 . 𝑐 + 31 . 𝑏1 . 𝑐

+ 32 . 𝑏 2 . 𝑐)

Hint: use Math.pow() under import .java.util.* declaration.

Your input is a, b, n for X queries . For the given input series, print the

corresponding series value in a single line separated by space.

Constraint
0≤X ≤5
0≤a,b,n ≤ 15
Sample Input

2
5345
02310
Sample Output

9 45 369 3285 29529

3 21 129 777 4665 27993 167961 1007769 6046617 36279705


import java.util.*;
import java.io.*;
public class Assignment1_1 {

public static void main(String []args){


Scanner in = new Scanner(System.in);
int q=in.nextInt();
for(inti=0;i<q;i++){
inta = in.nextInt();
intb = in.nextInt();
intc = in.nextInt();
intn = in.nextInt();
intd = a;
for(intj=0;j<n;j++){
d += Math.pow(3, j)*Math.pow(b,j)*c;
System.out.printf("%s ",d);
}
System.out.println();
}

You might also like