Java Programming Assignments, Assignments of Java Programming

Introduction to Java Programming Liang 10th Edition Exercises

Typology: Assignments

2021/2022

Uploaded on 01/18/2023

hasanzahid007
hasanzahid007 🇧🇩

2 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
North South University
Department of Electrical & Computer Engineering
Fall 2022
CSE215: Programming Language II
Homework 1
Submitted By
Zahid Hasan
ID: 1911509042
Section - 6
Submitted To
MR. RIFAT AHMED HASSAN
Lecturer
Department of Electrical &
Computer Engineering
Date of Submission: 26-11-2022
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Java Programming Assignments and more Assignments Java Programming in PDF only on Docsity!

North South University

Department of Electrical & Computer Engineering

Fall 2022

CSE215: Programming Language II

Homework 1

Submitted By

Zahid Hasan

ID: 1911509042

Section - 6

Submitted To

MR. RIFAT AHMED HASSAN

Lecturer

Department of Electrical &

Computer Engineering

Date of Submission: 26-11-

Answer to Problem 2.6:

import java.util.Scanner; public class Ex$2_6 { public static void main(String[] args){ System.out.print("Enter a number between 0 and 1000: "); Scanner input = new Scanner(System.in); int num = input.nextInt(); int firstDigit, secondDigit, thirdDigit; thirdDigit = num%10; num = num/10; secondDigit = num%10; num = num/10; firstDigit = num%10; System.out.println("the sum of the digits: "+(firstDigit+secondDigit+thirdDigit)); } } Output:

Answer to Problem 3.23:

import java.util.Scanner; public class Ex$3_23 { public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.print("Enter a point with two coordinates: "); double x = input.nextDouble(); double y = input.nextDouble(); if (x > (10/2.0) && y > (5/2.0)){ System.out.print("Point ("+x+","+y+") is not in the rectangle"); } else { System.out.print("Point ("+x+","+y+") is in the rectangle"); } } } Output:

Answer to Problem 4.18:

import java.util.Scanner; public class Ex$4_18 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter two characters: "); String user = input.nextLine(); char key1 = user.charAt(0); char key2 = user.charAt(1); String major = ""; String type = ""; int check = 0; switch(key1){ case 'M': major = "Mathematics"; break; case 'C': major = "Computer Science"; break; case 'I':

Output:

Answer to Problem 4.21:

import java.util.Scanner; public class Ex$4_21 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a SSN: "); String ssn = input.nextLine(); boolean isValid = (Character.isDigit(ssn.charAt(0))) && (Character.isDigit(ssn.charAt(1))) &&

(Character.isDigit(ssn.charAt(2))) && (ssn.charAt(3) == '-') && (Character.isDigit(ssn.charAt(4))) && (Character.isDigit(ssn.charAt(5))) && (ssn.charAt(6) == '-') && (Character.isDigit(ssn.charAt(7))) && (Character.isDigit(ssn.charAt(8))) && (Character.isDigit(ssn.charAt(9))) && (Character.isDigit(ssn.charAt(10))) && (ssn.length() == 11); System.out.println(ssn + " is " + ((isValid)? "a valid " : "an invalid ")

  • "social security number"); } } Output:

Answer to Problem 6.12:

public class Ex$6_12 { public static void main(String[] args){

public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Enter an integer: "); int num = input.nextInt(); reverse(num); } public static void reverse(int number){ int rem, rev = 0; while(number>0){ rem = number%10; rev = rev*10 + rem; number = number/10; } System.out.println("Reversed integer: "+rev); } } Output:

Answer to Problem 6.9:

public class Ex$6_9 { public static void main(String[] args){ double foot, meter; System.out.println("Feet Meters | Meters Feet"); System.out.println("---------------------------------- ---");

for(foot = 1, meter = 20; foot<=10; foot++,meter=meter+5){ System.out.printf("%4.1f %6.3f | %4.1f %6.3f",foot,footToMeter(foot),meter,meterToFoot(meter)); System.out.println(); } } public static double footToMeter(double foot){ double output = foot0.305; return output; } public static double meterToFoot(double meter){ double output = meter3.279; return output; } } Output: