Closed Java Program (CODECHUM)

Status
Not open for further replies.

ShinigamiNel

Honorary Poster
Pa help naman po dito mga sir. Nakahanap na ako ng code sa google tapos tini-tweak ko na lang para dun sa task. Anagram program po siya pero if may "?" sa input, pwedeng maging anagram pa rin basta pareho yung ibang letters
Example:
cat
dog
Output: false

nose
se?n
Output: anagram

?
a
Output: anagram

Ito po yung code tapos yung dulong part ang ginagawa ko di ko alam kung tama ba siya :(

package packagename;



import java.util.Arrays;
import java.util.Scanner;

class mainclassname
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);

// Getting the input string from the user

String s1 = scanner.nextLine();

String s2 = scanner.nextLine();

if(checkAnagram(s1, s2))
System.out.println("anagram");
else
System.out.println("false");

scanner.close();
}

public static boolean checkAnagram(String s1, String s2)
{
// Remove all the white space
s1 = s1.replaceAll("\\s", "");
s2 = s2.replaceAll("\\s", "");

// Check if both length matches
if(s1.length() != s2.length())
return false;
else
{

int length=s1.length();
// Convert both Strings into lower case and into Character Array
char[] arr1 = s1.toLowerCase().toCharArray();
char[] arr2 = s2.toLowerCase().toCharArray();

// Sort both Character Array
Arrays.sort(arr1);
Arrays.sort(arr2);

int count=0;
for(int i=0; i<length; i++){
if(arr1==arr2 || arr1=='?'){
count++;
if(count==length){
break;
}
}

}
return true;
}
}
}
 

Attachments

  • Screenshot_2020-12-16-13-17-26-107_com.android.chrome.webp
    Screenshot_2020-12-16-13-17-26-107_com.android.chrome.webp
    61.6 KB · Views: 36
  • Screenshot_2020-12-16-13-17-52-584_com.android.chrome.webp
    Screenshot_2020-12-16-13-17-52-584_com.android.chrome.webp
    28.3 KB · Views: 22
  • Screenshot_2020-12-16-13-18-02-870_com.android.chrome.webp
    Screenshot_2020-12-16-13-18-02-870_com.android.chrome.webp
    27.3 KB · Views: 23
  • Screenshot_2020-12-16-13-18-06-944_com.android.chrome.webp
    Screenshot_2020-12-16-13-18-06-944_com.android.chrome.webp
    28.8 KB · Views: 26
Did you know?

Web hosting is a service that allows organizations and individuals to post a website or web page onto the Internet. A web host, or web hosting service provider, is a business that provides the technologies and services needed for a website or webpage to be viewed on the Internet. Websites are hosted, or stored, on special computers called servers.

When Internet users want to view your website, all they need to do is type your website address or domain into their browser. Their computer will then connect to your server, and your webpages will be delivered to them through the browser.

When it comes to web hosting companies based on the number of hosted websites, GoDaddy has established itself as a clear market dominator. According to HostAdvice, GoDaddy has covered over 19% of the market, leaving a not-so-significant market share to other hosting providers such as Google Cloud Platform, 1&1, Amazon Web Services, and Cloudflare.

According to Builtwith, GoDaddy has also managed to become a world dominator when it comes to providing VPS web hosting. GoDaddy’s market share in this segment counts for over 23%, whereas its closest competitors, such as DreamHost and Digital Ocean, cover 1.46% and 1.23% of the market share, respectively.
Excuse me po. Na solve niyo na po ba yung test xase? Pwede po ba makahingi ng code. Same error lang din po sa akin di namimeet ng code ko yung lahat ng test case.
 
Actually nanghingi na lang din ako ng tulong sa coding god kong kaklase eh di talaga kinaya ng utak ko HAHAHAHA

Anyway, ito yung additional na code na nakapag pa-ayos dun sa program. Di ko lang makita yung full code kasi napasa na eh.



for(int i=0; i<length; i++){
if(arr1=='?'||arr2=='?')
count++;
else {
for(int j=0;j<length;j++) {
if(arr2[j]=='?') {
count++;
break;
}
if(arr1==arr2[j]) {
count++;
break;
}
}
}
 
Status
Not open for further replies.

Users search this thread by keywords

  1. codechum

About this Thread

  • 3
    Replies
  • 3K
    Views
  • 3
    Participants
Last reply from:
ShinigamiNel

Trending Content

Online now

Members online
365
Guests online
9,713
Total visitors
10,078

Forum statistics

Threads
2,032,210
Posts
27,568,541
Members
1,602,549
Latest member
Darryl pogi
Back
Top